﻿/*
 * My Timer - cdFormatting.cs
 * 
 * Copyright (C) 2009 Ahmad Hanis Azmi
 * 
 * This file is part of My Timer
 * 
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

namespace My_Timer.Formatting
{
    public class Formatting
    {
        public static string formatDaysHoursMinutesSecondsLong(int Days, int Hours, int Minutes, int Seconds, int One_Over_10_Seconds)
        {
            string s = "";

            if (Days > 0)
            {
                if (Days == 1)
                {
                    s = Days.ToString() + " day ";
                }
                else
                {
                    s = Days.ToString() + " days ";
                }
            }
            if (Hours > 0)
            {
                if (Days == 1)
                {
                    s = s + Hours.ToString() + " hour ";
                }
                else
                {
                    s = s + Hours.ToString() + " hours ";
                }
            }
            if (Minutes > 0)
            {
                if (Minutes == 1)
                {
                    s = s + Minutes.ToString() + " minute ";
                }
                else
                {
                    s = s + Minutes.ToString() + " minutes ";
                }
            }
            if (Seconds >= 0)
            {
                string ms = "";
                
                if (One_Over_10_Seconds != 0)
                {
                    ms = "." + One_Over_10_Seconds.ToString();
                }

                if (Seconds == 1)
                {
                    s = s + Seconds.ToString() + ms + " second ";
                }
                else
                {
                    s = s + Seconds.ToString() + ms + " seconds";
                }
            }

            if ((Days + Hours + Minutes + Seconds + One_Over_10_Seconds) == 0)
            {
                s = "0 second";
            }

            return s;
        }

        public static string formatDaysHoursMinutesSecondsShort(int Days, int Hours, int Minutes, int Seconds, int One_Over_10_Seconds)
        {
            string s = "";

            if (Days.ToString().Length == 1) { s = "0" + Days.ToString(); }
            else { s = Days.ToString(); }

            if (Hours.ToString().Length == 1) { s = s + ":0" + Hours.ToString(); }
            else { s = s + ":" + Hours.ToString(); }

            if (Minutes.ToString().Length == 1) { s = s + ":0" + Minutes.ToString(); }
            else { s = s + ":" + Minutes.ToString(); }

            if (Seconds.ToString().Length == 1) { s = s + ":0" + Seconds.ToString(); }
            else { s = s + ":" + Seconds.ToString(); }
            s = s + "." + One_Over_10_Seconds.ToString();

            return s;
        }
    }
}